//    Copyright (C) Kherty.  All rights reserved.
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using OpenLS.UI;

namespace OpenLS.Spreadsheet.UI
{
    /// <summary>
    /// Interaction logic for ZoomWindow.xaml
    /// </summary>

    public partial class ZoomControl 
    {

        public ZoomControl()
        {
            Resources.MergedDictionaries.Add(new DialogResources());
            InitializeComponent();
        }
        public bool FitToSelection
        {
            get{
                return this.fitToSelection.IsChecked.GetValueOrDefault();
            }
        }
        void OnPreviewTextInput(object sender, TextCompositionEventArgs args)
        {
            int i;
            if (!int.TryParse(args.Text, out i))
                args.Handled = true;
            args.Handled = !(i >= 10 && i <= 400);
        }
        public int Zoom
        {
            set
            {
                switch (value)
                {
                    case 200: percent200.IsChecked = true; break;
                    case 100: percent100.IsChecked = true; break;
                    case 75: percent75.IsChecked = true; break;
                    case 50: percent50.IsChecked = true; break;
                    case 25: percent25.IsChecked = true; break;
                    default: custom.IsChecked = true; this.customTextBox.Text = value.ToString(); break;
                }
            }
            get
            {
                if (percent200.IsChecked.GetValueOrDefault())
                    return 200;
                if (percent100.IsChecked.GetValueOrDefault())
                    return 100;
                if (percent75.IsChecked.GetValueOrDefault())
                    return 75;
                if (percent50.IsChecked.GetValueOrDefault())
                    return 50;
                if (percent25.IsChecked.GetValueOrDefault())
                    return 25;
                if (custom.IsChecked.GetValueOrDefault())
                    return int.Parse(customTextBox.Text);
                return 100;//\\
            }
        }
        void OnDoubleClick(object sender, MouseButtonEventArgs args)
        {
            RadioButton b = WindowServices.GetAncestor<RadioButton>(args.OriginalSource);
            if (b is RadioButton)
            {
                WindowServices.Close(this, true);
            }
        }

        private void customTextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            this.custom.IsChecked = true;
        }

    }
}